#ifndef _LOG_HPP_
#define	_LOG_HPP_

/*******************************************************************************
 ** Name: Log.hpp                                                             **
 ** Description:                                                              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  Redistribution and use in source and binary forms, with or without       **
 **  modification, are permitted provided that the following conditions are   **
 **  met:                                                                     **
 **                                                                           **
 **  * Redistributions of source code must retain the above copyright notice, **
 **    this list of conditions and the following disclaimer.                  **
 **  * Redistributions in binary form must reproduce the above copyright      **
 **    notice, this list of conditions and the following disclaimer in the    **
 **    documentation and/or other materials provided with the distribution.   **
 **                                                                           **
 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      **
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED **
 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           **
 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT        **
 ** HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    **
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  **
 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    **
 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    **
 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      **
 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        **
 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              **
 **                                                                           **
 ******************************************************************************/
// Created on March 24, 2010, 1:02 AM
// Modified $Date$ by $Author$

#define Log_hpp_ID   "$Id$"

#include <fstream>
#include <string>
#include <stdarg.h>
#include "common.hpp"

#define LOG_DATE    0x01
#define LOG_TIME    0x02
#define LOG_DATETIME 0x04
#define LOG_FUNC    0x08
#define LOG_LINE    0x10
#define LOG_DIR     "../data/"
#define LOG_DEBUG   1
#define LOG_INFO    2
#define LOG_IMPORT  3
#define LOG_CRIT    4
#define LOG_FATAL   5


//! Manages writing log files (including debug functionality)
class Log
{
public:
    Log(std::string fl);
    Log(const Log& orig) = delete;
    virtual ~Log();
    
    void    out(const char *, ...);
    void    out(int,const char *,...);

    bool    IsOK() const { return fileStream.is_open(); }
    int     SetFlag(int flag) { BMSET(flags,flag); return flags; }
    int     Flags() const { return flags; }
    uint8   Level(uint8 l = 0) { if (l) level = l; return level; }

private:
    std::string    fileName;
    bool            bIsOk;
    std::ofstream        fileStream;
    int             flags;
    uint8           level;
};

namespace debug {
extern Log * log;
}

#endif	/* _LOG_HPP_ */

